Strong modulation of THz optical properties of layered materials by thermal and ultrafast heating