Terrestrial planet and asteroid formation in the presence of giant planets. I. Relative velocities of planetesimals subject to Jupiter and Saturn perturbations.