Mobility restrictions for the control of epidemics: When do they work?