Threshold excitation of H2 and D2 by electron impact