Density of zeros of the Cartwright class functions and the Helson--Szeg\"o type condition