Temperature and energy gap dependence of energy transfer between rare-earth ions in solids