Removing infrared divergences from two-loop integrals