Heavy-quark production in massless quark scattering at two loops in QCD