BMW will be following Audi out of the electric Formula E series at the end of next year after announcing its departure on Wednesday.