Charge order and spin-singlet pair formation in Ti4O7