All the privileges and immunities from liability, exemptions from laws and rules, and all pension, relief, disability, workmen’s compensation and all other benefits granted the fire or police force of any local agency performing its functions within the territorial limits of such local agency shall extend and apply to such fire or police force performing its function within the territorial limits of any other local agency, and while traveling to and from such other local agency under and by virtue of any contract with such other local agency entered into under the provisions of this article.