Wave function matching for the quantum many-body problem