The AN form provides detailed guidance as to who can be your referee:

Below are the requirements for adult applications (AN).

For registration of children under 18 (MN1 applications), see Referees for children.


Your first referee

Referees must:
  • not be a relative, solicitor or agent of the applicant
  • not be related to the other referee
  • not be employed by the Home Office
  • know or have known the applicant personally for more than 3 years
  • they are willing to give full details of their knowledge of the applicant
  • advise the Home Office of any reason why the applicant should not be registered
Referees must also not have been convicted of an imprisonable offence. A single non-custodial sentence may be disregarded if:
  • it did not occur within the last 12 months
  • there is strong evidence showing that the referee is of good character
Give your first referee's details. This referee must be the holder of a British Citizen passport (and either a professional person or over the age of 25)
Your second referee

Give your second referee's details. This referee should be a person (of any nationality) who has professional standing. This can include a minister of religion, civil servant or a member of a professional body such as an accountant or solicitor (who is not representing you with this application).
See Professional Referees

The guidance does not specify that referees must be living in the UK, just that one of them must hold a British passport and the other one must be a professional as noted above.

The guidance also says:

If you are or the child is living abroad and do not know a British citizen who is qualified to act as one of your referees, a Commonwealth citizen or citizen of the country in which you are residing may complete and sign the form, provided they have professional standing in that country, has known you for 3 years and the Consul considers their signature to be acceptable.
If you are doing a family application (applying for more than one family member at the same time), the same referee can act for both of you, as long as they meet the criteria.

See Entering referee's details on the online AN form
Source: Nationality Policy: general information