Spectral slope variability of BL Lacertae objects in the optical band