CRISPR-based Herd Immunity Limits Phage Epidemics in Bacterial Populations