Formation of the 0.511 MeV line in solar flares