Two-spin correlation function for a Heisenberg magnet: Application to magnetostriction