Dynamics of Population Immunity Due to the Herd Effect in the COVID-19 Pandemic