The effect of impurities on the phase transitions in the ferroelectric semiconductors TlInS2 and TlGaSe2