Temporary capture of planetesimals by a giant planet and implication for the origin of irregular satellites