Different nature of instabilities in BaFe2As2 and BaNi2As2 as revealed by optical spectroscopy