We study the indirect exchange interaction of magnetic impurities via 2D excitations in a quantum well on the base of IV-VI narrow-gap semiconductors. The energy spectrum of 2D excitations takes into account the nonparabolicity of dispersion as well as the strong spin-orbit interaction. The calculations are performed for the case when the main mechanism is an exchange by virtual electron-hole pairs. It means that we assume the Fermi level to lie inside the energy gap, and the temperature to be small, T much-less-than epsilon0. It is shown that at large distances, R much-greater-than v/epsilon0 (2epsilon0 is the excitation energy for nearest size-quantized subbands, nu the interband interaction parameter), the antiferromagnetic interaction of pairs dominates, so that the impurity spins tend to be directed along the heterojunction plane perpendicular to the vector connecting the impurities. The interaction contains both the Heisenberg and pseudodipole terms.