They have generally similar meanings, but they are typically not interchangeable. In particular, there situations where only one of them can be used, and never the other.
In the context of prurience, "filthy" is typically used:
This movie is filthy (dirty would not be used here).
This book is filthy (dirty would not be used here).