Is there a way to filter out scratches on records when recording
No, but you can do it after recording.
a) there is the Click Removal effect in Audacity: https://manual.audacityteam.org/man/click_removal.html
b) personally I preferred to use Brian Davis’ excellent ClickRepair - it costs a little but produces almost magical results. See this sticky thread: https://forum.audacityteam.org/t/click-pop-removal-clickrepair-software/1933/1
WC