Dimensional reduction of the two Higgs doublet model at high temperature