Two-loop fermionic corrections to heavy-quark pair production: the quark-antiquark channel